package com.yxr.affairs;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import com.yxr.affairs.base.BaseActivity1;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Webview extends BaseActivity1 {
    @BindView(R.id.local_webview)
    WebView localWebview;
    private String url;
    @Override
    protected int attachLayoutRes() {
        return R.layout.view;
    }

    @Override
    protected void initViews() {

        url="http://www.jqsoft.net";
        loadLocalHtml(url);

    }


    @SuppressLint({ "JavascriptInterface", "SetJavaScriptEnabled" })
     public void loadLocalHtml(String url){
                WebSettings ws = localWebview.getSettings();
                ws.setJavaScriptEnabled(true);
        ws.setJavaScriptEnabled(true);
// 设置可以支持缩放
        ws.setSupportZoom(true);
// 设置出现缩放工具
      //  ws.setBuiltInZoomControls(true);
//扩大比例的缩放
        ws.setUseWideViewPort(true);
        localWebview.setInitialScale(100);
        ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        ws.setLoadWithOverviewMode(true);
        ws.setTextZoom(100);
        ws.setSaveFormData(false);
        ws.setJavaScriptEnabled(true);

        ws.setSupportZoom(false);
        ws.setSupportZoom(true);
        ws.setBuiltInZoomControls(true);
        ws.setTextSize(WebSettings.TextSize.SMALLER);
        ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);

//自适应屏幕



        //开启JavaScript支持
        localWebview.setWebViewClient(new WebViewClient(){
             @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                              //重写此方法，用于捕捉页面上的跳转链接
                                if ("http://start/".equals(url)){
                                         //在html代码中的按钮跳转地址需要同此地址一致
                                         Toast.makeText(getApplicationContext(), "开始体验", Toast.LENGTH_SHORT).show();
                                        finish();
                                    }
                                return true;
                             }
         });
        localWebview.loadUrl(url); }
    @Override
    protected void updateViews(boolean isRefresh) {

    }

    @Override
    protected void onError_(Throwable e) {

    }

    @Override
    protected void onCancel_() {

    }


}
